package com.gzu.finalwork.admin.controller;

import com.gzu.finalwork.admin.service.AdminDashboardService;
import com.gzu.finalwork.common.utils.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 管理员仪表盘控制器
 */
@RestController
@RequestMapping("/admin")
@CrossOrigin(origins = "http://localhost:5173", allowCredentials = "true")
public class AdminDashboardController {

    @Autowired
    private AdminDashboardService adminDashboardService;

    /**
     * 获取管理员仪表盘数据
     * @return 仪表盘统计数据
     */
    @GetMapping("/dashboard")
    public Object getDashboard() {
        try {
            return adminDashboardService.getDashboardData();
        } catch (Exception e) {
            return AjaxResult.error(500, "获取仪表盘数据失败：" + e.getMessage());
        }
    }

    /**
     * 获取今日新订单数
     * @return 今日新订单数
     */
    @GetMapping("/dashboard/today-orders")
    public Object getTodayOrders() {
        try {
            return adminDashboardService.getTodayOrders();
        } catch (Exception e) {
            return AjaxResult.error(500, "获取今日订单数失败：" + e.getMessage());
        }
    }

    /**
     * 获取订单统计概览
     * @return 订单统计数据
     */
    @GetMapping("/dashboard/order-stats")
    public Object getOrderStats() {
        try {
            return adminDashboardService.getOrderStats();
        } catch (Exception e) {
            return AjaxResult.error(500, "获取订单统计失败：" + e.getMessage());
        }
    }

    /**
     * 获取收入统计
     * @return 收入统计数据
     */
    @GetMapping("/dashboard/revenue-stats")
    public Object getRevenueStats() {
        try {
            return adminDashboardService.getRevenueStats();
        } catch (Exception e) {
            return AjaxResult.error(500, "获取收入统计失败：" + e.getMessage());
        }
    }
} 